// const util = require('../../utils/util.js')
let animation = wx.createAnimation({})
Page({
  /**
   * 页面的初始数据
   */
  data: {
    animation: "",
    snNumber: "",
    isShowModal: false,
    inputVal: "",
    modalTitle: "输入设备号",
    placeholder: "请输入设备号",
    inputType: "text",
    showDesc: "",
    id: "",
    name: "",
    getCode: false,
    scanRes: ""
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      id: options.plotId,
      name: options.plotName
    })
  },
  scancode(e) {
    let res = e.detail.result
    if (this.data.getCode || this.data.scanRes == res) {
      return
    }
    if (!this.data.isShowModal) {
      // inputVal: res,
      this.setData({
        scanRes: res,
        inputVal: res,
        getCode: true
      })
      // this.checkDevice()
    }
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.anmi()
    this.setData({
      scanRes: "",
      getCode: false
    })
  },
  anmi() {
    var that = this
    // 控制向上还是向下移动
    let m = true

    setInterval(
      function () {
        if (m) {
          animation.translateY(100).step({
            duration: 3000
          })
          m = !m
        } else {
          animation.translateY(10).step({
            duration: 3000
          })
          m = !m
        }

        that.setData({
          animation: animation.export()
        })
      }.bind(this),
      3000
    )
  },

  clickInput() {
    this.setData({
      isShowModal: true
    })
  },
  customBindInput(e) {
    this.setData({
      inputVal: e.detail
    })
  },
  cancle() {
    this.setData({
      isShowModal: false
    })
  },
  confirm(e) {
    wx.setStorage({
      key: "snNumber",
      data: {
        snNumber: this.data.snNumber
      },
      success: function () {
        wx.navigateBack() //返回上一个页面
      }
    })
    this.setData({
      isShowModal: false
    })
  },

  bindDevice: function () {}
})
